//
//  IDVC.m
//  renyikan
//
//  Created by Steven on 2019/7/16.
//  Copyright © 2019 Steven. All rights reserved.
//

#import "IDVC.h"

@interface IDVC ()
@property(nonatomic,weak)IBOutlet UITextField *inputTF;

@property (weak, nonatomic) IBOutlet UILabel *areaLabel;

@property (weak, nonatomic) IBOutlet UILabel *sexLabel;
@property (weak, nonatomic) IBOutlet UILabel *birthdayLabel;

@end

@implementation IDVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
}

- (IBAction)searchAction:(UIButton *)sender{
    [self.view endEditing:YES];
    
    if (self.inputTF.text.length == 0) {
        
        [MBProgressHUD showError:@"请输入身份证号！"];
        
        return;
    }
    
    __weak typeof(self) weakSelf = self;
    [JFNetworkingManager requestWithURLString:[NSString stringWithFormat:@"http://apis.juhe.cn/idcard/index?key=d32fc411c0fb9d7c011fbb6003ded2ff&cardno=%@",self.inputTF.text ] parameters:nil type:HttpRequestTypePost view:self.view success:^(id responseObject) {
        
        weakSelf.areaLabel.hidden = false;
        weakSelf.areaLabel.text = responseObject[@"result"][@"area"];
        
        weakSelf.sexLabel.hidden = false;
        weakSelf.sexLabel.text = responseObject[@"result"][@"sex"];
        
        weakSelf.birthdayLabel.hidden = false;
        weakSelf.birthdayLabel.text = responseObject[@"result"][@"birthday"];
        
    } failure:^(NSError *error) {
        
    }];

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

@end
